1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.Credentials; 26 27 private import gio.c.functions; 28 public import gio.c.types; 29 private import glib.ConstructionException; 30 private import glib.ErrorG; 31 private import glib.GException; 32 private import glib.Str; 33 private import glib.c.functions; 34 private import gobject.ObjectG; 35 36 37 /** 38 * The #GCredentials type is a reference-counted wrapper for native 39 * credentials. This information is typically used for identifying, 40 * authenticating and authorizing other processes. 41 * 42 * Some operating systems supports looking up the credentials of the 43 * remote peer of a communication endpoint - see e.g. 44 * g_socket_get_credentials(). 45 * 46 * Some operating systems supports securely sending and receiving 47 * credentials over a Unix Domain Socket, see 48 * #GUnixCredentialsMessage, g_unix_connection_send_credentials() and 49 * g_unix_connection_receive_credentials() for details. 50 * 51 * On Linux, the native credential type is a `struct ucred` - see the 52 * unix(7) man page for details. This corresponds to 53 * %G_CREDENTIALS_TYPE_LINUX_UCRED. 54 * 55 * On Apple operating systems (including iOS, tvOS, and macOS), 56 * the native credential type is a `struct xucred`. 57 * This corresponds to %G_CREDENTIALS_TYPE_APPLE_XUCRED. 58 * 59 * On FreeBSD, Debian GNU/kFreeBSD, and GNU/Hurd, the native 60 * credential type is a `struct cmsgcred`. This corresponds 61 * to %G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED. 62 * 63 * On NetBSD, the native credential type is a `struct unpcbid`. 64 * This corresponds to %G_CREDENTIALS_TYPE_NETBSD_UNPCBID. 65 * 66 * On OpenBSD, the native credential type is a `struct sockpeercred`. 67 * This corresponds to %G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED. 68 * 69 * On Solaris (including OpenSolaris and its derivatives), the native 70 * credential type is a `ucred_t`. This corresponds to 71 * %G_CREDENTIALS_TYPE_SOLARIS_UCRED. 72 * 73 * Since GLib 2.72, on Windows, the native credentials may contain the PID of a 74 * process. This corresponds to %G_CREDENTIALS_TYPE_WIN32_PID. 75 * 76 * Since: 2.26 77 */ 78 public class Credentials : ObjectG 79 { 80 /** the main Gtk struct */ 81 protected GCredentials* gCredentials; 82 83 /** Get the main Gtk struct */ 84 public GCredentials* getCredentialsStruct(bool transferOwnership = false) 85 { 86 if (transferOwnership) 87 ownedRef = false; 88 return gCredentials; 89 } 90 91 /** the main Gtk struct as a void* */ 92 protected override void* getStruct() 93 { 94 return cast(void*)gCredentials; 95 } 96 97 /** 98 * Sets our main struct and passes it to the parent class. 99 */ 100 public this (GCredentials* gCredentials, bool ownedRef = false) 101 { 102 this.gCredentials = gCredentials; 103 super(cast(GObject*)gCredentials, ownedRef); 104 } 105 106 107 /** */ 108 public static GType getType() 109 { 110 return g_credentials_get_type(); 111 } 112 113 /** 114 * Creates a new #GCredentials object with credentials matching the 115 * the current process. 116 * 117 * Returns: A #GCredentials. Free with g_object_unref(). 118 * 119 * Since: 2.26 120 * 121 * Throws: ConstructionException GTK+ fails to create the object. 122 */ 123 public this() 124 { 125 auto __p = g_credentials_new(); 126 127 if(__p is null) 128 { 129 throw new ConstructionException("null returned by new"); 130 } 131 132 this(cast(GCredentials*) __p, true); 133 } 134 135 /** 136 * Gets a pointer to native credentials of type @native_type from 137 * @credentials. 138 * 139 * It is a programming error (which will cause a warning to be 140 * logged) to use this method if there is no #GCredentials support for 141 * the OS or if @native_type isn't supported by the OS. 142 * 143 * Params: 144 * nativeType = The type of native credentials to get. 145 * 146 * Returns: The pointer to native credentials or 147 * %NULL if there is no #GCredentials support for the OS or if @native_type 148 * isn't supported by the OS. Do not free the returned data, it is owned 149 * by @credentials. 150 * 151 * Since: 2.26 152 */ 153 public void* getNative(GCredentialsType nativeType) 154 { 155 return g_credentials_get_native(gCredentials, nativeType); 156 } 157 158 /** 159 * Tries to get the UNIX process identifier from @credentials. This 160 * method is only available on UNIX platforms. 161 * 162 * This operation can fail if #GCredentials is not supported on the 163 * OS or if the native credentials type does not contain information 164 * about the UNIX process ID. 165 * 166 * Returns: The UNIX process ID, or `-1` if @error is set. 167 * 168 * Since: 2.36 169 * 170 * Throws: GException on failure. 171 */ 172 public pid_t getUnixPid() 173 { 174 GError* err = null; 175 176 auto __p = g_credentials_get_unix_pid(gCredentials, &err); 177 178 if (err !is null) 179 { 180 throw new GException( new ErrorG(err) ); 181 } 182 183 return __p; 184 } 185 186 /** 187 * Tries to get the UNIX user identifier from @credentials. This 188 * method is only available on UNIX platforms. 189 * 190 * This operation can fail if #GCredentials is not supported on the 191 * OS or if the native credentials type does not contain information 192 * about the UNIX user. 193 * 194 * Returns: The UNIX user identifier or `-1` if @error is set. 195 * 196 * Since: 2.26 197 * 198 * Throws: GException on failure. 199 */ 200 public uid_t getUnixUser() 201 { 202 GError* err = null; 203 204 auto __p = g_credentials_get_unix_user(gCredentials, &err); 205 206 if (err !is null) 207 { 208 throw new GException( new ErrorG(err) ); 209 } 210 211 return __p; 212 } 213 214 /** 215 * Checks if @credentials and @other_credentials is the same user. 216 * 217 * This operation can fail if #GCredentials is not supported on the 218 * the OS. 219 * 220 * Params: 221 * otherCredentials = A #GCredentials. 222 * 223 * Returns: %TRUE if @credentials and @other_credentials has the same 224 * user, %FALSE otherwise or if @error is set. 225 * 226 * Since: 2.26 227 * 228 * Throws: GException on failure. 229 */ 230 public bool isSameUser(Credentials otherCredentials) 231 { 232 GError* err = null; 233 234 auto __p = g_credentials_is_same_user(gCredentials, (otherCredentials is null) ? null : otherCredentials.getCredentialsStruct(), &err) != 0; 235 236 if (err !is null) 237 { 238 throw new GException( new ErrorG(err) ); 239 } 240 241 return __p; 242 } 243 244 /** 245 * Copies the native credentials of type @native_type from @native 246 * into @credentials. 247 * 248 * It is a programming error (which will cause a warning to be 249 * logged) to use this method if there is no #GCredentials support for 250 * the OS or if @native_type isn't supported by the OS. 251 * 252 * Params: 253 * nativeType = The type of native credentials to set. 254 * native = A pointer to native credentials. 255 * 256 * Since: 2.26 257 */ 258 public void setNative(GCredentialsType nativeType, void* native) 259 { 260 g_credentials_set_native(gCredentials, nativeType, native); 261 } 262 263 /** 264 * Tries to set the UNIX user identifier on @credentials. This method 265 * is only available on UNIX platforms. 266 * 267 * This operation can fail if #GCredentials is not supported on the 268 * OS or if the native credentials type does not contain information 269 * about the UNIX user. It can also fail if the OS does not allow the 270 * use of "spoofed" credentials. 271 * 272 * Params: 273 * uid = The UNIX user identifier to set. 274 * 275 * Returns: %TRUE if @uid was set, %FALSE if error is set. 276 * 277 * Since: 2.26 278 * 279 * Throws: GException on failure. 280 */ 281 public bool setUnixUser(uid_t uid) 282 { 283 GError* err = null; 284 285 auto __p = g_credentials_set_unix_user(gCredentials, uid, &err) != 0; 286 287 if (err !is null) 288 { 289 throw new GException( new ErrorG(err) ); 290 } 291 292 return __p; 293 } 294 295 /** 296 * Creates a human-readable textual representation of @credentials 297 * that can be used in logging and debug messages. The format of the 298 * returned string may change in future GLib release. 299 * 300 * Returns: A string that should be freed with g_free(). 301 * 302 * Since: 2.26 303 */ 304 public override string toString() 305 { 306 auto retStr = g_credentials_to_string(gCredentials); 307 308 scope(exit) Str.freeString(retStr); 309 return Str.toString(retStr); 310 } 311 }